package ru.gerunn.parsing.service;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

import org.hibernate.Session;

import ru.gerunn.parsing.tables.DefaultLog;
import ru.gerunn.parsing.tables.DefaultOperation;
import ru.gerunn.parsing.tables.DefaultType;

public class LogParserRunnable<Type extends DefaultType, Operation extends DefaultOperation<Type>, Log extends DefaultLog<Operation>> implements Runnable {

	LogHandler<Type, Operation, Log> logHandler;

	public LogParserRunnable(Session session, String logParserName, Pattern logParserPattern, Class<Type> typeClass, Class<Operation> operationClass, Class<Log> logClass, String dir, String prefix) {
		LogParser<Type, Operation, Log> logParser = new LogParser<Type, Operation, Log>(
			session,
			logParserName,
			logParserPattern,
			typeClass,
			operationClass,
			logClass
		);

		List<LogParser<Type, Operation, Log>> parsers = new ArrayList<LogParser<Type, Operation, Log>>();
		parsers.add(logParser);

		LogProvider logProvider = new LogProvider(
			dir,
			prefix,
			logParser.getTimestamp()
		);

		this.logHandler = new LogHandler<Type, Operation, Log>(
			logProvider,
			parsers
		);

	}

	public void run() {
		logHandler.handle();
	}

}
